package com.lingnan.blog.mapper;

import com.lingnan.blog.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommentMapper {
    /**
     * 根据文章id查询评论数据
     *
     * @param aid
     * @return
     */
    @Select("select * from comment where a_id = #{aid}")
    List<Comment> selectAllByAId(Integer aid);

    /**
     * 插入评论数据
     *
     * @param comment
     * @return
     */
    @Insert("insert into comment values (null,#{uId},#{aId} ,#{content} ," +
            "#{cmtime} ,0 ,#{photo}, #{nickname} )")
    int insert(Comment comment);

    @Select("select * from comment where u_id = #{uid} and a_id = #{aid}")
    Comment selectByUIdAndAId(@Param("uid") String uid, @Param("aid") Integer aid);
}